
package hk.ces.oxfam.patch.result;

import hk.ces.oxfam.patch.obj.Bean;
import hk.ces.oxfam.patch.obj.BeanPacker;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ReutyCheng
 */
public class BaseBeanResult<T extends Bean> implements BeanResult<T>
{
  private final List<T> beans;

  public BaseBeanResult(DataResult dataResult, BeanPacker<T> packer)
  {
    this(dataResult.getResultsList(), packer);
  }

  public BaseBeanResult(List<Object[]> resultsList, BeanPacker<T> packer)
  {
    this.beans = new ArrayList<T>(resultsList != null ? resultsList.size() : 0);
    for (Object[] results : resultsList)
    {
      this.beans.add(packer.pack(results));
    }
  }

  public List<T> getBeans()
  {
    return this.beans;
  }

  public T getResultsValue(int resultsIndex)
  {
    return this.beans.get(resultsIndex);
  }

  public int getBeansCount()
  {
    return this.beans.size();
  }

  public boolean isBeansRmpty()
  {
    return this.beans.isEmpty();
  }
}
